﻿@{
    Bundle("jquery_validate");
}
           
<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery('@ID("#form")').validate({
            rules: {
                ownerName: {
                    required: true
                },
                folderID: {
                    required: true,
                    digits: true
                },
                file: {
                    required: true
                },
                name: {
                    required: true
                }
            }
        });
        jQuery('@ID("#txt_owner")').autocomplete({
            source: function (request, response) {
                jQuery.post('@Html.Raw(Url.Action(Loc.Act("Autocomplete").Ctrl("Owner")))', request, response);
            },
            minLength: 3,
            select: function (event, ui) {
                jQuery('@ID("#hidden_owner")').val(ui.item.id);
            }
        });
        jQuery.ajax({
            type: 'post',
            url: '@Url.Action(Loc.Act("Storages").Ctrl("File"))',
            dataType: 'json',
            success: function (rsp) {
                var ddl = jQuery('@ID("#ddl_storage")');
                ddl.empty();
                jQuery.each(rsp, function (k, v) {
                    ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                });
            }
        });
    });
</script>
<form id="@ID("form")" action="@Url.Action(Loc.Act("Create").Ctrl("File"))" method="post" enctype="multipart/form-data">
    <input type="hidden" name="flags" value="None" />
    <table>
        <tr>
            <td>
                <label>@T(Res.Name("Storage"))</label>
            </td>
            <td>
                <select id="@ID("ddl_storage")" name="storageID"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Owner"))</label>
            </td>
            <td>
                <input id="@ID("hidden_owner")" type="hidden" name="ownerID" />
                <input id="@ID("txt_owner")" type="text" name="ownerName" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Folder"))</label>
            </td>
            <td>
                <input type="text" name="folderID" value="0" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("File"))</label>
            </td>
            <td>
                <script type="text/javascript">
                    jQuery(document).ready(function () {
                        jQuery('@ID("#file")').change(function () {
                            jQuery('@ID("#txt_name")').val(jQuery(this).val().split('\\').pop());
                        });
                    });
                </script>
                <input id="@ID("file")" type="file" name="file" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Name"))</label>
            </td>
            <td>
                <input id="@ID("txt_name")" type="text" name="name" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("API").Of("Enum").Of("FileFlags").Name("Active"))</label>
            </td>
            <td>
                <input type="checkbox" name="flags" value="Active" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("API").Of("Enum").Of("FileFlags").Name("Public"))</label>
            </td>
            <td>
                <input type="checkbox" name="flags" value="Public" />
            </td>
        </tr>
    </table>
    <ul class="bar toolbar">
        <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
    </ul>
</form>
